/*
 * **********************************************************
 * include files
 * **********************************************************
 */

#include "stm32f1xx.h"
#include "BSP.h"
#include "Register.h"
#include "usart.h"
#include "EEPROM.h"
#include "ModbusRtu.h"
#include "ModbusRegister.h"
#include "24cxx.h"
#include "IDriver.h"
#include "FrmDisplay.h"
#include "DefrostControl.h"
#include "Timer.h"
#include "Alarm.h"
#include "CompressorControl.h"
#include "GetAnalog.h"
#include "ADScan.h"
#include "FanControl.h"
#include "DewControl.h"
#include "JD_InOut.h"
#include "Control.h"
/****************Include  Section  Begin***************************************************/


/****************Struct Definition Section Begin*********************************************/
#define F_NUM (9)
extern u8	Set_Modbus_Address(	u8 index	,	u8	address	);
extern s16 ModbusRTUMaster_SlaveComFault(void);
//extern u8	RegistReadFlag;


extern u8 TempDefrostProgress;
extern u8 StopSecond;
extern u16 StopMinute; //
extern u32 RunMinute; //
extern u32 DuraTime;
extern u16 DefRunRunMinute;
s16 CascadedParam[4];


typedef struct
{
	s16 min;
	s16 max;
	s16 defaultValue1;
	s16 defaultValue2;
	s16 defaultValue3;
	s16 defaultValue4;
	s16 defaultValue5;
	s16 defaultValue6;
	s16 defaultValue7;
	s16 defaultValue8;
	s16 defaultValue9;
	s16 defaultValue10;
	s16 defaultValue11;
	s16 defaultValue12;
	s16 defaultValue13;
	s16 defaultValue14;
	s16 defaultValue15;
	s16 defaultValue16;
	s16 defaultValue17;
	s16 defaultValue18;
	s16 defaultValue19;
	s16 defaultValue20;
	s16 defaultValue21;
	s16 defaultValue22;
	s16 defaultValue23;
	s16 defaultValue24;
	s16 defaultValue25;
	s16 defaultValue26;
	s16 defaultValue27;
	s16 defaultValue28;
	s16 defaultValue29;
	s16 defaultValue30;
	s16 defaultValue31;
	s16 defaultValue32;
	s16 defaultValue33;
	s16 defaultValue34;
	s16 defaultValue35;
	s16 defaultValue36;
	
  u8 dec;
} PARAM_LIMIT;

typedef struct
{
	s16 min;
	s16 max;
	s16 defaultValue;
  u8 dec;       //?????
        
} PARAM_LIMIT1;

s16 Param_Values[PARAM_AMOUNT];

/*
 * Function Name:	ParameterLimit
 * Description:	������
 * Note:	����ΪPARAM_AMOUNT�Ķ���,����Flash��,ȫ����Ĭ��ֵ
 */

const PARAM_LIMIT	ParameterLimit[PARAM_AMOUNT] =
{

               //1				2				3				4				5				6				7				8				9			10			11			12			13			14			15			16			17			18			19			20			21			22			23			24			25			26			27			28			29			30			31			32			33			34			35			36
{-40,   99,      0,  	   0,  	   2,      0,      2,     -5,     -5,    	 5,   	 3,    -32,    -32,     -4,   	-4,   	-4,     -6,    -25,  	 -28,    -30,  	 -32,  	 -32,  	  -5,     -5,  	 -32,	 	-25,  	 -32,    -32,  		-5,  	   0,   	-4,  	   3,    -22,   	 2,   	-4,     -4,    -22,  	   2,   0,}, 
{1,     15,      2,   	 2,  	   2,  	   2,  	   2,      2,	     2,	     2,  	   2,	     2,   	 2, 	   2,	     2,	     2,	     2,      2,	     2,	     2,    	 2,	     2,	     2,	     2,	     2,	    2,	     2,	     2,  	   2,	     2,	     2,			 4,	     4,      4,      2,	     2,	    4,  	   4,   0,},
{-10,   10,      0,   	 0,	     0,	     0,  	   0,   	 0, 	   0, 	   0,	     0,      0,	     0,	     0,	     0,	     0,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	    0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	    0,   		 0,		0,},
{-10,   11,      0,	     0,	     0,  	   0,	     0,	     0,	     0,	     0,  	   0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,      0,     0,     	 0,      0,	     0,	     0,	     0,	     0,	     0,      0,	     0,	     0,	    0,   		 0,		0,},
{-10,   11,     11,	     0,	    11,	    11, 	   0,	    11,	     0,	    11,	    11,	    11,	     0,	    11,	     0,     11,	    11,	    11,	    11,	    11,	    11,	    11,	    11,	    11,	    11,	   11,	    11,	    11,			11,      0,	     0,	    11,    	11, 	  11,	    11,	    11,	    11,	    11,		0,},
{-10,   11,      0,      0,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,     0,	     0,	     0,	     0,	     0,	     0,    	 0,	     0,	     0,	     0,	     0,      0,   	 0,		0,},
{0,     99,     15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,    	15,	    15,	    15,    	15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,	    15,   	15,		0,},
{1,     99,      8,      8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,	     8,		   8,   0,},
{0,     10,      2,      2,	     2,	     2,	     2,	     0,	     0,	     2,	     2,	     0,	     0,	     2,	     2,	     2,	     2,	     0,	     2,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,			 2,	     2,	     0,	     0,	     0,      2,	     2,	     0,	     0,   0,},
{-40,   99,     15,	    15,	    17,	    15,	    17,	    10,	    10,	    20,	    18,	    -7,	    -7,	    11,	    11,	    11,	     9,	     0,	    -3,	    -5,	    -7,	    -7,	    10,	    10,			-7,	     0,	    -7,	    -7,	    10,	    17,	    11,	    20,	    -7,	    17,	    11,	    11,	    -7,	    17,   0,},
	//10~19
{0,    251,      5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,	     5,      5,	     5,	     5,	     5,	    5,    	 5,		0,},
{-40,   99,     -5,    	-5,	    -3,	    -5,	    -3,	   -10,	   -10,	     0,	    -2,	   -37,	   -37,	    -9,	    -9,    	-9,	   -11,	   -30,	   -33,	   -35,	   -37,	   -37,	   -10,	   -10,	   -37,	   -30,	   -37,	   -37,	   -10,	    -3,	    -9,	     0,	   -37,	    -3,	    -9,	    -9,	   -37,	    -3,   0,},
{0,    251,     60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,    	60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,   	60,		0,},
{0,    250,     60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,	    60,   	60,		0,},
{-40,   99,     55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,	    55,   	55,		0,},
{-40,   99,     47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,	    47,   	47,		0,},
{0,    250,    180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,	   180,    180,		0,},
{0,      3,      0,	     3,	     0,	     0,	     3,	     0,	     3,	     0,	     0,	     0,	     3,	     0,	     3,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,		0,	     0,	     0,	     3,	     3,	     3,	     3,	     0,	     0,	     0,	     0,	     0,	     0,	     	 0,   0,},
{6,     25,     15,	    15,	    15,	    15,	    15,	    10,	    10,	    15,	    15,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    13,	    13,	    10,	    10,	    10,		10,	    10,	    10,	    10,	    10,	    15,	    10,	    15,	    15,	    12,	    10,	    10,	    15,	    	12,   0,},
{0,     15,      3,	     3,	     3,	     3,	     3,	     3,	     3,	     3,	     3,	     5,	     5,	     3,	     3,	     3,	     3,	     5,	     5,	     5,	     5,	     5,	     3,	     3,		5,	     5,	     5,	     5,	     3,	     3,	     3,	     3,	     5,	     3,	     3,	     3,	     5,	     	 3,   0,},
//20~29
{1,     99,     30,	    30,	    30,	    30,	    30,	    30,	    30,	    30,	    30,	    40,	    40,	    30,	    30,	    30,	    30,	    40,	    40,	    40,	    40,	    40,	    30,			30,	    40,	    40,	    40,	    40,	    30,	    30,	    30,	    15,	    40,	    30,	    30,	    30,    	40,	    30,   0,},
{0,     99,     10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,			10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,	    10,   0,},
{6,    180,     24,	    24,	    24,	    24,	    24,	    36,	    36,	    24,	    24,	    72,	    72,	    24,	    24,	    24,	    24,	    36,	    36,	    72,	    72,	    72,	    36,	    24,			36,	    72,	    72,	    72,	    36,	    24,	    24,	    24,	    72,	    36,	    24,	    24,	    72,	    36,   0,},
{0,      2,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     2,	     2,	     0,	     0,	     0,		   0,	     0,	     0,	     2,	    2,	     2,	     0,			0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     1,	     2,	     0,	     0,	     1,	     2,   0,},
{0,      1,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   	0,		0,},
{0,      2,      2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,   	2,		0,},
{0, 0x2400,    0x0,	   0x0,	0x0000,	0x0000,	0x0000,	0x0200,	0x0200,	0x0000,	0x0000,	0x0800,	0x0800,	   0x0,	   0x0,	   0x0,	   0x0,	0x0200,	0x0200,	0x0800,	0x0800,	0x0800,	0x0200,		 0x0,	0x0200,	0x0800,	0x0800,	0x0800,	0x0200,	0x0000,	   0x0,	   0x0,	0x0800,	0x0200,	   0x0,	   0x0,	0x0800,	0x0200,   0,},
{0, 0x2400, 0x0400,	0x0400,	0x0400,	0x0400,	0x0400,	0x0800,	0x0800,	0x0400,	0x0400,	0x2000,	0x2000,	0x0400,	0x0400,	0x0400,	0x0400,	0x0800,	0x0800,	0x2000,	0x2000,	0x2000,	0x0800,	0X0400,	0x0800,	0x2000,	0x2000,	0x2000,	0x0800,	0x0400,	0x0400,	0x0400,	0x2000,	0x0800,	0x0400,	0x0400,	0x2000, 0x0800,   0,},
{0, 0x2400, 0x0800,	0x0800,	0x0800,	0x0800,	0x0800,	0x1400,	0x1400,	0x0800,	0x0800,	0x2400,	0x2400,	0x0800,	0x0800,	0x0800,	0x0800,	0x1400,	0x1400,	0x2400,	0x2400,	0x2400,	0x1400,	0X0800,	0x1400,	0x2400,	0x2400,	0x2400,	0x1400,	0x0800,	0x0800,	0x0800,	0x2400,	0x1400,	0x0800,	0x0800,	0x2400,	0x1400,   0,},
{0, 0x2400, 0x1200,	0x1200,	0x1200,	0x1200,	0x1200,	0x2000,	0x2000,	0x1200,	0x1200,	0x2400,	0x2400,	0x1200,	0x1200,	0x1200,	0x1200,	0x2000,	0x2000,	0x2400,	0x2400,	0x2400,	0x2000,	0x1200,	0x2000,	0x2400,	0x2400,	0x2400,	0x2000,	0x1200,	0x1200,	0x1200,	0x2400,	0x2000,	0x1200,	0x1200,	0x2400,	0x2000,   0,},
//30~39
{0, 0x2400, 0x1600,	0x1600,	0x1600,	0x1600,	0x1600,	0x2400,	0x2400,	0x1600,	0x1600,	0x2400,	0x2400,	0x1600,	0x1600,	0x1600,	0x1600,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x1600,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x1600,	0x1600,	0x1600,	0x2400,	0x2400,	0x1600,	0x1600,	0x2400,	0x2400,   0,},
{0, 0x2400, 0x2000,	0x2000,	0x2000,	0x2000,	0x2000,	0x2400,	0x2400,	0x2000,	0x2000,	0x2400,	0x2400,	0x2000,	0x2000,	0x2000,	0x2000,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2000,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2000,	0x2000,	0x2000,	0x2400,	0x2400,	0x2000,	0x2000,	0x2400,	0x2400,   0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0,},
{0,      3,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,			 0,   0,},
{1,     99,      1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,			 1,   0,},
//40~49
{0,      2,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,			 0,   0,},
{0,     30,      9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,			 9,   0,},
{0,     99,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   	 0,		0,},
{0, 0x0212, 0x0000,	0x0100,	0x0001,	0x0101,	0x0201,	0x0002,	0x0102,	0x0003,	0x0103,	0x0004,	0x0104,	0x0005,	0x0105,	0x0006,	0x0106,	0x0007,	0x0107,	0x0008,	0x0108,	0x0208,	0x0009,	0x0109,	0x0209,	0x000A,	0x010A,	0x000B,	0x010B,	0x000C,	0x000D,	0x000E,	0x000F,	0x010F,	0x0010,	0x0011,	0x0012,	0x0112,   0,},
{-40,   99,     20,	    20,	    20,	    20,	    20,	    20,	    20,	    20,	    20,	   -10,	   -10,	    20,	    20,	    20,	    20,	   -10,	   -10,	   -10,	   -10,	   -10,	    20,	   20,		-10,	   -10,	   -10,	   -10,	    20,	    20,	    20,	    20,	   -10,	    20,	    20,	    20,	   -10,	    20,   0,},
{-40,   99,    -10,	   -10,	   -10,	   -10,	   -10,	   -10,	   -10,	   -10,	   -10,	   -35,	   -35,	   -10,	   -10,	   -10,	   -10,	   -35,	   -35,	   -35,	   -35,	   -35,	   -10,	   -10,		-35,	   -35,	   -35,	   -35,	   -10,	   -10,	   -10,	   -10,	   -35,	   -10,	   -10,	   -10,	   -35,	   -10,   0,},
{0,     30,      9,	    18,	     9,	     9,	    18,	     9,	    18,	     9,	     9,	     9,	    18,	     9,	    18,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,	     9,		 	 9,	    18,	    18,	     9,	     9,	     9,	     9,	     9,	     9,	     9,   0,},
{0,     99,      0,	     1,	     0,	     0,	     1,	     0,	     1,	     0,	     0,	     0,	     1,	     0,	     1,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,		 	 0,	     1,	     1,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   0,},
{0,      3,      2,	     2,	     2,	    2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,	     2,			2,		0,},
{0,     240,    240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,	   240,		240,  0,},
//50~59
{0,    240,      0,	     0,	     0,	    0,	    0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   	0,		0,},
{0,      2,      1,	     1,	     1,	    1,	    1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,	     1,   	1,		0,},
{0,     99,      0,	     0,	     0,	    0,	    0,	     0,	     0,	     0,	     0,	     1,	     1,	     0,	     0,	     0,	     0,	     0,	     0,	     1,	     1,	     1,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,		 	 0,	     1,	     1,	     0,	     0,	     1,	   	1,    0,},
{-40,   50,    -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,	   -30,  	-30,		0,},
{-40,   50,     50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,	    50,    50,		0,},
{0,      2,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   	0,		0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0x2400,	0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0x2400,	0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0x2400,	0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0x2400,	0,},
//60~64
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0x2400,	0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0x2400,	0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0x2400,	0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,   0x2400,	0,},
{0, 0x2359, 0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,	0x2359,   0x2359,	0,},
//65-71
{0,      6,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   		0,	0,},
{0,      1,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   		0,	0,},
{0,   	 2,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   		0,	0,},
{0,   	 1,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   		0,	0,},
{0,      1,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   		0,	0,},
{0,      1,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   		0,	0,},
{0,      1,      0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,	     0,   		0,	0,},
//72~79
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400, 0x2400,		0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400, 0x2400,		0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400, 0x2400,		0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400, 0x2400,		0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400, 0x2400,		0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400, 0x2400,		0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400, 0x2400,		0,},
{0, 0x2400, 0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400,	0x2400, 0x2400,		0,},

};

const PARAM_LIMIT1	ParameterLimit2[4] =
{
		{	   0 , 1, 0,  0 },	//	900
		{	   0 , 2, 0,  0 },	//	901
		{	   -100 , 100, 0,  1 },	//	902	
		{	   -100 , 100, 0,  1 },	//	903
};

u8 GetControllerTypeNum(u16 ControllerTpye)
{
    switch (ControllerTpye)
    {

    case 0x0000:
		case 0x0100:
		case 0x0001:
		case 0x0101:
		case 0x0201:
		case 0x0002:
		case 0x0102:
		case 0x0003:
		case 0x0103:
		case 0x0004:
		case 0x0104:
		case 0x0005:
		case 0x0105:
		case 0x0006:
		case 0x0106:
		case 0x0007:
		case 0x0107:
		case 0x0008:
		case 0x0108:
		case 0x0208:
		case 0x0009:
	  case 0x0109:
		case 0x0209:
		case 0x000A:
		case 0x010A:
		case 0x000B:
		case 0x010B:
		case 0x000C:
		case 0x000D:
		case 0x000E:
		case 0x010F:
		case 0x000F:
		case 0x0010:
		case 0x0011:
		case 0x0012:
	  case 0x0112:
		return 1;
    default:
      return 0;
    }
}

u8 SetLowAndMiddleControllerType()
{
	u8 Type,NcFt,LdLc = 0;
  u16 ControllerType;
	Type = GetJDParamValue(HREG_CONTROLLER_TYPE_SET)&0x00FF;
	NcFt = (GetJDParamValue(HREG_CONTROLLER_TYPE_SET)&0xFF00)>>8;
	switch(Type)
	{
		case 0x02:              //CSM
			if(NcFt)
			{	
				ControllerType = 0x0104;
				LdLc = 1;        //�䶳
				SetParamRegisterValue(HREG_CONTROLLER_TYPE_SET,ControllerType);						
			}
			else
			{
				LdLc = 1; 
				ControllerType = 0x0004;
				SetParamRegisterValue(HREG_CONTROLLER_TYPE_SET,ControllerType);
			}
		break;
		
		case 0x04:              //CZM
			if(NcFt)
			{	
				LdLc = 2; 
				ControllerType = 0x0102;
				SetParamRegisterValue(HREG_CONTROLLER_TYPE_SET,ControllerType);						
			}
			else
			{
				LdLc = 2; 
				ControllerType = 0x0002;
				SetParamRegisterValue(HREG_CONTROLLER_TYPE_SET,ControllerType);
			}
		break;
		
		
		case 0x0B:             //TEM
			if(NcFt)
			{
				LdLc = 1; 
				ControllerType = 0x000B;
				SetParamRegisterValue(HREG_CONTROLLER_TYPE_SET,ControllerType);
			
			}
			else
			{
				LdLc = 2; 
				ControllerType = 0x010B ;
				SetParamRegisterValue(HREG_CONTROLLER_TYPE_SET,ControllerType);
			}
		
		break;
		default:
				LdLc = 0;
		 break;
		
	}
	return LdLc;
}



u8 GetControllerType2Max(u8 ControllerTpye1)
{
    switch (ControllerTpye1)
    {

    case 1://2
           return 2;    
    case 8://9
          return 2;
		case 9: //10
					return 2;
    case 12: 
    case 13:   
    case 14:
    case 16:
		case 17:
          return 0;	
    default:
      return 1;
    }
}


/*
 * Function Name:GetDefaultSet
 * Description:	?????????
 * Return Value:	
 * Parameter:	
 * 				
 * Note:
 */




u8	Modbus_Master_Update_Input(u8 address, u16 registerLoca, s16 registerValue)
{
	if(address != 1)
	{
		return (u8)1;
	}
	switch(registerLoca)
	{
	default:return (u8)0;
	}
}

u8	Modbus_Master_Update_Holding(u8 address, u16 registerLoca, s16 registerValue)
{
	if(address != 1)
	{
		return (u8)1;
	}
	switch(registerLoca)
	{

	default:return (u8)0;
	}
}

/*
 * Function Name:   Params_Get_Stored_Value
 * Description: ????????
 * Return Value:    s16 ??16?????
 * Parameter:   index   ?????
 * Note:
 */
s16 Params_Get_Stored_Value(u16 index)
{
    if (index < PARAM_AMOUNT)
    {
        return Param_Values[index];
    }
    else
    {
        return ILoad_Stored_Value(index);
    }
}

/*
 * Function Name:	Param_Get_MAX
 * Description:	???????
 * Return Value:	
 * Parameter:	index	?????
 * Note:
 */
s16 Param_Get_MAX(u16 index)
{
    if (index < PARAM_AMOUNT)
    {
        if (HREG_CONTROL_SET_POINT == index)
        {
            return ILoad_Stored_Value(HREG_SETPOINT_MAX * 2);
        }
        else  if (HREG_LOW_ALARM_TEMP == index)
        {
            return ILoad_Stored_Value(HREG_CONTROL_SET_POINT * 2);
        }
				  else  if (HREG_CONDERSER_RELIEVE_ALARM_TEMP == index)
        {
            return ILoad_Stored_Value(HREG_CONDERSER_ALARM_TEMP * 2);
        }
				else  if (HREG_EVAPORATOR_FAN_WORK_LOW_TEMP == index)
        {
            return ILoad_Stored_Value(HREG_EVAPORATOR_FAN_WORK_HIGH_TEMP * 2);
        }
					  else  if (HREG_SETPOINT_MIN == index)
        {
            return ILoad_Stored_Value( HREG_SETPOINT_MAX* 2);
        }
        else
        {
            return ParameterLimit[index].max;
        }
    }
		else if((index >= HREG_CASCADED_MODE_ENABLE)&&(index <= HREG_CASCADED_VALVE_DOWN_DEVIATION))	
		{
				return  ParameterLimit2[index-HREG_CASCADED_MODE_ENABLE].max;
		}
    else
    {
        return (s16)32767;
    }
}

/*
 * Function Name:	Param_Get_MIN
 * Description:	???????
 * Return Value:
 * Parameter:	index	?????
 * Note:
 */
s16 Param_Get_MIN(u16 index)
{
    if (index < PARAM_AMOUNT)
    {
        if (HREG_CONTROL_SET_POINT == index)
        {
            return ILoad_Stored_Value(HREG_SETPOINT_MIN * 2);
        }

        else  if (HREG_HIGH_ALARM_TEMP == index)
        {
            return ILoad_Stored_Value(HREG_CONTROL_SET_POINT * 2);
        }
        else  if (HREG_EVAPORATOR_FAN_WORK_HIGH_TEMP == index)
        {
            return ILoad_Stored_Value(HREG_EVAPORATOR_FAN_WORK_LOW_TEMP * 2);
        }
				  else  if (HREG_SETPOINT_MAX == index)
        {
            return ILoad_Stored_Value(HREG_SETPOINT_MIN * 2);
        }
        else
        {
            return ParameterLimit[index].min;
        }
    }
		else if((index >= HREG_CASCADED_MODE_ENABLE)&&(index <= HREG_CASCADED_VALVE_DOWN_DEVIATION))	
		{
				return  ParameterLimit2[index-HREG_CASCADED_MODE_ENABLE].min;
		}
    else
    {
        return (s16)-32768;
    }
}

/*
 * Function Name:	Param_Get_Default
 * Description:	???????
 * Return Value:	s16	??16?????,???????0
 * Parameter:	index	?????
 * Note:
 */
s16 Param_Get_Default(u16 index, u16 Channel)
{
    if (index < PARAM_AMOUNT)
    {
        switch (Channel)
        {
        case 0x0000:
            return ParameterLimit[index].defaultValue1;
			  case 0x0100:
            return ParameterLimit[index].defaultValue2;
				case 0x0001:
            return ParameterLimit[index].defaultValue3;
				case 0x0101:
            return ParameterLimit[index].defaultValue4;
				case 0x0201:
            return ParameterLimit[index].defaultValue5;
				case 0x0002:
            return ParameterLimit[index].defaultValue6;
				case 0x0102:
            return ParameterLimit[index].defaultValue7;
				case 0x0003:
            return ParameterLimit[index].defaultValue8;
				case 0x0103:
            return ParameterLimit[index].defaultValue9;
				case  0x0004:
            return ParameterLimit[index].defaultValue10;
				case  0x0104:
            return ParameterLimit[index].defaultValue11;
				case  0x0005:
            return ParameterLimit[index].defaultValue12;
				case  0x0105:
            return ParameterLimit[index].defaultValue13;
				case  0x0006:
            return ParameterLimit[index].defaultValue14;
				case  0x0106:
            return ParameterLimit[index].defaultValue15;
				case  0x0007:
            return ParameterLimit[index].defaultValue16;
				case  0x0107:
            return ParameterLimit[index].defaultValue17;
				case  0x0008:
            return ParameterLimit[index].defaultValue18;
				case  0x0108:
            return ParameterLimit[index].defaultValue19;
				case  0x0208:
            return ParameterLimit[index].defaultValue20;
				case  0x0009:
            return ParameterLimit[index].defaultValue21;
				case  0x0109:
            return ParameterLimit[index].defaultValue22;
				case  0x0209:
            return ParameterLimit[index].defaultValue23;			
				case  0x000A:
            return ParameterLimit[index].defaultValue24;
				case  0x010A:
            return ParameterLimit[index].defaultValue25;
				case  0x000B:
            return ParameterLimit[index].defaultValue26;
				case  0x010B:
            return ParameterLimit[index].defaultValue27;
				case 0x000C:
            return ParameterLimit[index].defaultValue28;
				case  0x000D:
            return ParameterLimit[index].defaultValue29;
				case  0x000E:
            return ParameterLimit[index].defaultValue30;
				case 0x000F:
            return ParameterLimit[index].defaultValue31;
				case 0x010F:
            return ParameterLimit[index].defaultValue32;
				case 0x0010:
            return ParameterLimit[index].defaultValue33;
				case 0x0011:
            return ParameterLimit[index].defaultValue34;
				case 0x0012:
            return ParameterLimit[index].defaultValue35;
				case 0x0112:
            return ParameterLimit[index].defaultValue36;
        default:
            return (s16)0;
        }
    }
    else
    {
        return (s16)0;
    }
}

/*
 * Function Name:	Param_Check_Value
 * Description:	????????
 * Return Value:	u8	??8?????,0???,?0???,1????,2????
 * Parameter:	location	?????
 * 				value	?????
 * Note:
 */
u8 Param_Check_Value(u16 index, s16 value)
{
    if (value > Param_Get_MAX(index))
    {
        return (u8)1;
    }
    else if (value < Param_Get_MIN(index))
    {
        return (u8)2;
    }
    else
    {
        return (u8)0;
    }
}

/*
 * Function Name:	Params_Init_By_Stored
 * Description:
 * Return Value:	u8
 * Parameter:
 * Note:
 */
u8 Params_Init_By_Stored(u16 channel)
{
	u16 i, j;
	u8 flag = 0;
	if ((channel&0x00FF) > 0x0012)
	{
		channel = 0;
		IStore_Value(HREG_CONTROLLER_TYPE_SET*2, 0);
		Param_Values[HREG_CONTROLLER_TYPE_SET] = 0;
		IStore_Value(HREG_HOUR_MINUTE*2, 0);
		IStore_Value(HREG_DEFOST_MANUAL*2, 0);

	}

	if (ILoad_Stored_Value(EE_APPNEW_FLAG) != PARAM_INIT_FLAG_VALUE)
	{
		if (ILoad_Stored_Value(EE_APPNEW_FLAG) != PARAM_INIT_FLAG_VALUE)
		{
			IStore_Value(HREG_SETPOINT_MAX*2, Param_Get_Default(HREG_SETPOINT_MAX, channel));
			IStore_Value(HREG_SETPOINT_MIN*2, Param_Get_Default(HREG_SETPOINT_MIN, channel));
			flag = 1;
		}
	}


	for (i = 0; i < PARAM_AMOUNT; i++)
	{
		j = i * 2;

		switch (i)
		{
			case HREG_CONTROLLER_TYPE_SET:
			case HREG_HOUR_MINUTE:
			case HREG_ADDRESS:
//			case HREG_DEFOST_MANUAL:
//			case HREG_DEW_COMM:

			break;

			default:

			if (Param_Check_Value(i, ILoad_Stored_Value(j)) || flag)
			{
				IStore_Value(j, Param_Get_Default(i, channel));
			}

			if (ILoad_Stored_Value(j) > Param_Get_MAX(i))
			{
				IStore_Value(j, Param_Get_MAX(i));
			}
			else if (ILoad_Stored_Value(j) < Param_Get_MIN(i))
			{
				IStore_Value(j, Param_Get_MIN(i));
			}
			IWDG_ReloadCounter();

			SetJDParamValue(i, ILoad_Stored_Value(j));

			break;
		}

		if (Param_Values[i] != ILoad_Stored_Value(j))
		{
			Param_Values[i] = ILoad_Stored_Value(j);
		}
	}

	if (flag)
	{
		IStore_Value(EE_APPNEW_FLAG, PARAM_INIT_FLAG_VALUE);
	}

	return (u8)0;
}
s16 GetComnTempValue(u8 chanel)
{
	s16 value;
	value = IGet_AI_Scaled_Value(chanel);;
	if(value == 32001)
	{
		value = -99;
	}
	else 	if(value == 32002)
	{
		value = -98;
	}
	else
	{
		value = GetIntegerTemp(chanel);
	}

	return value;
}

u16 GetWarnAndDIValue()
{
	u16 Value;
	u16 WarnValue = 0;
  Value = IGet_Warn_States();
	if(Value&0x00FF)
	{
		WarnValue|= 0x08;
	}
	
	if(Value&0x0200)
	{
		WarnValue|= 0x01;
	}
	if(Value&0x0100)
	{
		WarnValue|= 0x02;
	}
	if(Value&0x0800)
	{
		WarnValue|= 0x04;
	}
	if(GetModbusRTUMaster_FailCount(1	, 3)>=10)
	{
		WarnValue|= 0x10;
	}
	if( Controller.ManualCommand >= COOL_FAN_OFF)
	{
		WarnValue|= 0x80;
	}
	return WarnValue;
}

u16 GetDOAndDEFTypeValue()
{
	u16 Value;
	u16 StatusValue =0;
   Value = IGet_DO_States(0);
	if(Value&GetJDParamValue(HREG_DEFROST_TYPE))
	{
		StatusValue|= 0x01;
	}
	
	if(Value&0x0008)
	{
		StatusValue|= 0x02;
		
	}
	if(Value&0x0001)
	{
		StatusValue|= 0x08;
	}
	if(Value&0x0010)
	{
		StatusValue|= 0x10;
	}
  if(Value&0x0004)
	{
		StatusValue|= 0x20;
	}
	 if(Value&0x0002)
	{
		StatusValue|= 0x40;
	}
	
	if(Value&0x0040)
	{
		StatusValue|= 0x80;
	}
	
  return StatusValue;
}

s16 checkRestFlag(void)
{
	s16 flag = 0;
	
	if(__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET )
	{
		flag = 1;
	}
	if(__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET )
	{
		flag = 2;
	}
	if(__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET )
	{
		flag = 3;
	}
	if(__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET )
	{
		flag = 4;
	}
	if(__HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST) != RESET )
	{
		flag = 5;
	}
	if(__HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST) != RESET )
	{
		flag = 6;
	}
	//__HAL_RCC_CLEAR_RESET_FLAGS();
	
	return flag;
	
}


/*
 * Function Name:   GetJDDSCStatuesValue
 * Description: ??Input????
 * Return Value:    s16 ??16?????
 * Parameter:   index   ?????
 * Note:
 */
s16 GetJDStatuesValue(u16 address)
{
	switch (address)
	{
		case REG_GOODS_TEMP : 
			return GetComnTempValue(GOODS_TEMP);
		case REG_DEF_TEMP :
			if(NOT_USED == GetJDParamValue(HREG_DEF_CALI))
			{
				return -100;
			}				
			return GetComnTempValue(DEFRPST_TEMP);
		case REG_CONDENSER_TEMP : 
			if(NOT_USED == GetJDParamValue(HREG_CONDENSER_CALI))
			{
				return -100;
			}
			return GetComnTempValue(CONDENSER_TEMP);
		case REG_CONTROL_TEMP : 
			if(NOT_USED == GetJDParamValue(HREG_CONTROL_CALI))
			{
				return -100;
			}
			return GetComnTempValue(CONTROL_TEMP);
		case REG_SENSOR5_TEMP :
			return 0;
		case REG_CONTROLLER_STATUS : 
			return IGet_Controller_States();
		case REG_RUN_TIMER:
			if (DEFROST_WAIT != Controller.Defrost.Progress)
			{
				return DefRunRunMinute;   
			}
			else if(COOL_ON == GetControlCommand())
			{
				return RunMinute/10;
			}
			else
			{
				return StopMinute/10;
			}
		case REG_DURA_TIME:
			return DuraTime;
		case REG_RESET_FLAG:
			return checkRestFlag();
		case REG_WARN_AND_DI:
			return GetWarnAndDIValue();
		case REG_DO :
			return  GetDOAndDEFTypeValue();
		case REG_DI :
			return IGet_DI_States(0);
		case REG_HARD_VERISION:
			return HARD_VERSION;
		case REG_SOFTWARE_VISION:
			return SOFTWARE_VERSION;		
		case REG_COMP_MIN_RUN_TIMER:
			if(Controller.Compressor.MinRunTimerDelay!=TIMER_NOT_USED)
			{
				return Controller.Compressor.MinRunTimerDelay;
			}
			else
			{
				return 0;
			}
		case REG_COMP_MIN_STOP_TIMER:
			if(Controller.Compressor.MinStopTimerDelay!=TIMER_NOT_USED)
			{
				return Controller.Compressor.MinStopTimerDelay;
			}
			else
			{
				return 0;
			}	
		case REG_AUTORUN_FLAG   :   
			return Controller.Compressor.AutoRunFlag;
		case REG_AUTORUN_RUNSTOP_TIMER  :  
			if(Controller.Compressor.DutyCyclTimerDelay!=TIMER_NOT_USED)
			{
				return Controller.Compressor.DutyCyclTimerDelay;
			}
			else
			{
				return 0;
			}
		case REG_DEFROST_PROGRESS  :
			return Controller.Defrost.Progress;	
		case REG_DEFROST_TIME  :  
			if(Controller.Defrost.TimerDelay!=TIMER_NOT_USED)
			{
				return Controller.Defrost.TimerDelay;
			}
			else
			{
				return 0;
			}
		case REG_PERIOD_DEFROST_NEXT_DEFROST_TIMER_DELAY  :
			return Controller.Defrost.DefrostMaxTimerInterval;
		case REG_DFROST_OVER_SHIELD_TIMER_DELAY :
			return Controller.Defrost.DefrostTimerDelay; 

		//�����õ�ַ	 

		case REG_CASCADED_GOODS_TEMP:
			return GetDecimalTemp(GOODS_TEMP);

		case REG_CONTROLLER_STATE:
			if( Controller.ManualCommand >= COOL_FAN_OFF)	
			{ 
				return 3;
			}					
			else	if((DEFROST_WAIT != Controller.Defrost.Progress))
			{
				return 2;
			}
			else if(IGet_DO_State(DO1_COOL) == 1)
			{
				return 1;
			}
			else 
			{
				return 0;
			}		

		case REG_OPEN_ESV_TEMP:
			return 		GetEsvOpenTemp();					 
		case REG_COLSED_ESV_TEMP:
			return 	GetEsvCloseTemp();			 
		case REG_CONTROLLER_TYPE:
			return CONTROLLER_TYPE;
		default:
			return (s16)999;
	}
}
/*
 * Function Name:   GetJDDSCParamValue
 * Description:    ??Hold???????
 * Return Value:    s16 ??16?????
 * Parameter:   index   ?????
 * Note:
 */

s16 GetJDParamValue(u16 Address)
{
    if((Address >= HREG_CASCADED_MODE_ENABLE)&&(Address <= HREG_CASCADED_VALVE_DOWN_DEVIATION))	
    {
        return CascadedParam [Address - HREG_CASCADED_MODE_ENABLE];;
    }
    else if (Address >= PARAM_AMOUNT)
    {
        return 0;
    }
    else if (Address == HREG_HOUR_MINUTE)
		{
				return (( IGet_ReadTime(2))/10*16+( IGet_ReadTime(2))%10)<<8 |(( IGet_ReadTime(1))/10*16+( IGet_ReadTime(1))%10);
		}
		else
    {
        return Param_Values[Address];
    }
}


/*
 * Function Name:   GetParamDec
 * Description: ?????????
 * Return Value:
 * Parameter:   index   ?????
 * Note:
 */
u8 GetParamDec(u16 index)
{
    if (index >= PARAM_AMOUNT)
        return 0;
    else
        return ParameterLimit[index].dec;
}

/*
 * Function Name:   SetParamValue
 * Description: ???????
 * Return Value:    s16 ??16?????
 * Parameter:   index   ?????
 * Note:
 */
void SetParamValue(u16 Address, s16 Value)
{
    if (Address >= PARAM_AMOUNT)
    {
        return;
    }
    else if (Address < PARAM_AMOUNT)
    {
        Param_Values[Address] = Value;
    }
}

void SetHourAndMinute(u16 Value)
{
	u16 tempHour = 0;
	u16 tempminute = 0;
	tempHour = (Value>>8)/16*10+ (Value>>8)%16;
	tempminute = (Value&0xFF)/16*10+ (Value&0xFF)%16;
	ISet_ReadTime(2,tempHour);
	ISet_ReadTime(1,tempminute);
}


/*
 * Function Name:   SetJDDSCParamValue
 * Description: ??HoldRegister????
 * Return Value:    s16 ??16?????
 * Parameter:   index   ?????
 * Note:
 */
u8 SetJDParamValue(u16 location, s16 Value)
{

    SetParamValue(location, Value);
    switch (location)
    {
			
			case HREG_SYS_MODE:
					
			   Controller.ManualCommand = Value;

			   break;			
			case HREG_ADDRESS:
			
			  SetComWait(2);
				ISet_Modbus_SlaveAddress(UART_INDEX_2, Value);
				Set_Modbus_Address(UART_INDEX_2, IGet_Modbus_SlaveAddress(UART_INDEX_2));      
       
        break;
			
      case HREG_HOUR_MINUTE:		  
			  SetHourAndMinute(Value);
       break;   
      case HREG_GOODS_CALI:
				ISet_AI_Cali_Value(ANALOG_IN_INDEX_1,  Value);
        break;
      case HREG_DEF_CALI:
			  if((Value == 11)&&((GetJDParamValue(HREG_EVAPORATOR_FAN_MODE)==2)))
				{
					 SetParamRegisterValue( HREG_EVAPORATOR_FAN_MODE,   1 );
				}
				else  if(Value != 11)
				{
					ISet_AI_Cali_Value(ANALOG_IN_INDEX_2 , Value);
				}
        break;
      case HREG_CONDENSER_CALI:
			 if(Value != 11)
			 {
				ISet_AI_Cali_Value(ANALOG_IN_INDEX_3 , Value);
			 }
        break;
      case HREG_CONTROL_CALI:
				if(Value != 11)
				{
				ISet_AI_Cali_Value(ANALOG_IN_INDEX_0 , Value);
				}
        break;
			case HREG_TWO_DEFROST_MAX_TIME_INTERVAL:
			
			  Controller.Defrost.DefrostMaxTimerInterval =  Value*10;
			  break;
			case HREG_DEFOST_MANUAL:
        if (1 == Value || 0x55 == Value)
        {
					if ( Controller.System_Time_Delay > 0)
          {
            Controller.System_Time_Delay = 0	;		
          }
            Controller.Defrost.DefrostManual = 1;            					
        }    
				else if(2 == Value)
				{
            Controller.Defrost.DefrostManual = 2;
						if(Param_Values[location] != 0)
            {
                Param_Values[location] = 0;
            }
        }
				else 
        {
            Controller.Defrost.DefrostManual = 0;
        }
				SetParamValue(location, 0);
        break;			
	    case HREG_DEW_COMM:
        if (1 == Value || 0x55 == Value)
        {
					 Controller.ManualDew = 1;          					
        }
				else 
        {
            Controller.ManualDew = 0; 
        }
				SetParamValue(location, 0);
        break;								
			case	HREG_LINGTING_COMM:
				if(1== Value)
				{
				  if(Controller.light.Manual == 1)
				  {
						Controller.light.Manual = 0;
				  }
			   	else
			   	{
					  Controller.light.Manual = 1;
				  }
			  }
				else 	if(2== Value)
				{
          Controller.light.Manual = 1;	   
			  }
				else 	if(4== Value)
				{
          Controller.light.Manual = 0;	   
			  }
				break;
			case HREG_CONTROLLER_TYPE_SET:
				
				IStore_Value(EE_APPNEW_FLAG, 0);
			
        Params_Init_By_Stored(ILoad_Stored_Value(HREG_CONTROLLER_TYPE_SET*2));
			
				break;
			
			case	HREG_EVAPORATOR_FAN_MODE:
				if((GetJDParamValue(HREG_DEF_CALI)==11)&&(Value == 2))
				{
					IStore_Value(HREG_EVAPORATOR_FAN_MODE*2, 1);
					SetParamValue(location, 1);				
				}
		
		}

    return 0;
}

/*
 * Function Name:IGet_Controller_States
 * Description:	?????
 * Return Value:
 * Parameter:
 *
 * Note:
 */

u8 IGet_Controller_States()
{
    u8 ControllerState = 0;
//    if ( Controller.ManualCommand >= COOL_FAN_OFF)
//    {
//        ControllerState = EMPTY_PROCESS;
//    }
//    else 
    if ((DEF_ON_DELAY == Controller.Defrost.Progress) || (DEF_ON == Controller.Defrost.Progress) )
    {
        ControllerState = DEFROST_PROCESS;
    }
    else if ((DRIP_DELAY == Controller.Defrost.Progress)|| (DRIP == Controller.Defrost.Progress))
    {
        ControllerState = DRIPING_PROCESS;
    }
    else if (((COOL_STATUS == Controller.Status)||(DUTY_COOLING_STATUS== Controller.Status)||(CASCADED_STATUS== Controller.Status))&&((IGet_DO_State(DO1_COOL) == 1)))
    {
        ControllerState = COOLING_PROCESS;
    }
		else
		{
			ControllerState = KEEP_COOL_PROCESS;
		}
    return ControllerState;
}

